package cn.study.controller;


import cn.study.entity.StudyBanner;
import cn.study.entity.StudyCourse;
import cn.study.entity.StudyScore;
import cn.study.service.StudyScoreService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 成绩表 前端控制器
 * </p>
 *
 * @author qiao
 * @since 2020-06-22
 */
@Controller
@Slf4j
@RequestMapping("/study-score")
public class StudyScoreController {
    @Resource
    private StudyScoreService studyScoreService;
    @GetMapping("/list")
    public String list(Model model, @RequestParam(value="pn",defaultValue="1") Integer pn,
                       @RequestParam(value="paginalsize",defaultValue = "5") Integer paginalsize)
    {
        PageHelper.startPage(pn, paginalsize);

        List<StudyScore> list=studyScoreService.getlist();
        PageInfo pInfo=new PageInfo(list,10);
        model.addAttribute("pInfo",pInfo);
        model.addAttribute("paginalsize",paginalsize);

        return "study_score";
    }
    @GetMapping("/upd")
    public String upd(Integer id,Model model)
    {
        StudyScore studyScore=studyScoreService.getById(id);
        model.addAttribute("list",studyScore);


        return "study_score_upd";
    }

    @PostMapping("/scoreupd")
    public String scoreupd(Model model,StudyScore studyScore)
    {
        studyScoreService.updateById(studyScore);
        return "redirect:/study-score/list";
    }

}

